package com.stephen.redisdemo;

import java.util.*;

/**
 * @author: stephen
 * @create: 2020-02-28 16:29
 * @description:
 */
public class ArrayListDemo {

    public static void main(String[] args) {
        // 线程不安全的集合,java.util.ConcurrentModificationException
        List<Integer> list1 = new ArrayList<>();
        // 线程安全的集合
        /**
         * 加了synchronized
         */
        List<Integer> list2 = new Vector<>();
        /**
         * 用synchronized包装了一层
         */
        List<Integer> list3 = Collections.synchronizedList(new ArrayList<>());

        Set<String> set = Collections.synchronizedSet(new HashSet<>());

        Map<String,String> map = new Hashtable<>();
        Collections.synchronizedMap(new HashMap<>());


        for (int i = 0; i < 30; i++) {
            new Thread(()-> {
                map.put(Thread.currentThread().getName(),UUID.randomUUID().toString().substring(0,8));
                System.out.println(map);
            },String.valueOf(i)).start();
        }

    }
}
